var vm = new Vue({
    el:"#improveInfo",
    data:{
        list: {//完善信息列表
            account:localStorage.getItem('account'),
            name:'',
            tel:'',
            phone:'',
            postcode:'',
            country:'',
            city:'',
            town:'',
            addr:'',
            company_name:'',
            user_name:'',
            email:''
        },
        codeList:[],
        codeInfo:''
    },
    methods:{
        // 提交信息
        submit:function () {
            var url = '/userweb/login/information';
            var data = {
                data:this.list
            };
            var res = check( this.list );
            if ( !res[ 'flag' ] ) {
                layer.msg( res[ 'msg' ],{
                    skin:'winning-class',
                    time:3000
                });
                return false;
            }
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    layer.msg("完善信息成功</br>Perfect information success",{
                        skin:'winning-class',
                        time:3000
                    });
                    location.href = "/userweb/index/index.html";
                } else {
                    layer.msg(res.data.msg,{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }, function (res) {

            });
        },
        // 获取邮编地址
        getAddr:function () {
            if (this.list.postcode == ''){
                layer.msg('请输入店铺邮编</br>Please enter the zip code of the store',{
                    skin:'winning-class',
                    time:3000
                });
                return;
            }
            var url = '/userweb/login/zipCode';
            var data = {
                postcode:this.list.postcode
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    if (''== res.data.data.list || undefined ==res.data.data.list){
                        layer.msg('该邮编不存在(post code is not exist)!',{
                            skin:'winning-class',
                            time:3000
                        });
                        return;
                    }
                    this.codeList = res.data.data.list;
                    showAddress();
                } else {
                    layer.msg(res.data.msg,{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }, function (res) {

            });

        },
        codeAdd:function (list) {
            this.list.postcode      = list.postal_code;
            this.list.country       = list.admin_name1;
            this.list.city          = list.admin_name2;
            this.list.town          = list.admin_name3;
            this.list.addr          = list.addr;
        }
    },

    mounted: function () {

    }
});
function check(data) {
    console.log(data)
    var arr = [];
    if ( !data[ 'name' ] ) {
        arr[ 'msg' ] = "请输入店铺名称！";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( !data[ 'tel' ] ) {
        arr[ 'msg' ] = "请输入商铺电话！";
        arr[ 'flag' ] = false;
        return arr;
    }
    //手机验证
    if (!data[ 'phone' ]){
        arr[ 'msg' ] = "请输入联系人电话！";
        arr[ 'flag' ] = false;
        return arr;
    }
    //手机验证
    if (data[ 'tel' ]){
        if (!checkTel(data['phone'])){
            arr[ 'msg' ] = "请输入正确的电话！";
            arr[ 'flag' ] = false;
            return arr;
        } ;
    }
    if (data[ 'phone' ]){
        if (!checkTel(data['phone'])){
            arr[ 'msg' ] = "请输入正确的电话！";
            arr[ 'flag' ] = false;
            return arr;
        } ;
    }
    if ( !data[ 'postcode' ]) {
        arr[ 'msg' ] = "请输入店铺邮编";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( !data[ 'addr' ]) {
        arr[ 'msg' ] = "请输入店铺地址！";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( !data[ 'company_name' ]) {
        arr[ 'msg' ] = "请输入公司名称！";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( !data[ 'user_name' ]) {
        arr[ 'msg' ] = "请输入联系人！";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( !data[ 'email' ]) {
        arr[ 'msg' ] = "请输入邮箱！";
        arr[ 'flag' ] = false;
        return arr;
    }
    //邮箱验证
    if (data[ 'email' ]){
        if (!checkEmail(data[ 'email' ])){
            arr[ 'msg' ] = "请输入正确的邮箱！";
            arr[ 'flag' ] = false;
            return arr;
        };

    }
    arr[ 'flag' ] = true;
    return arr;
}